home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Sample Code / Snippets / Development Tools & Languages / DTSCPlusLibrary / Sources / FileClassTest.cp < prev    next >
Encoding:
Text File  |  1993-01-14  |  2.9 KB  |  90 lines  |  [TEXT/MPS ]

  1. /* _________________________________________________________________________________________________________ //
  2.   Copyright © 1992-93 Apple Computer, Inc. All rights reserved.
  3.   Macintosh Developer Technical Support.C++ Macintosh Toolbox Framework.
  4.   Programmer: Kent Sandvik
  5.   Date: 12/27/92
  6.   Revision comments are at the end of this file.
  7.   ---
  8.   TFile is a simple object that does file manipulations    
  9.   TFileTest.cp contains the TFile class and subclass test functions. 
  10.   _________________________________________________________________________________________________________ */
  11.  
  12. #ifndef _FILECLASS_
  13. #include "FileClass.h"
  14. #endif
  15.  
  16. const short kSize = 5;
  17.  
  18. // This is a simple test that will try to create, open, store and retrieve data
  19. // from files.
  20.  
  21. void main(void)
  22. {
  23.     cout << "Start of the TFile object test…\n";
  24.  
  25.     cout << "\nTest x: Create File and get File info (FInfo)…\n";
  26.     TDataFile myFile("Test File 1");
  27.     myFile.Create();
  28.     FInfo myInfo = myFile.GetFileInfo();
  29.     cout << "File signature is " << myInfo.fdCreator << "\n";
  30.  
  31.  
  32.     cout << "\nTest x:Rename and open the file…\n";
  33.     myFile.Rename("Test File 2");
  34.     myFile.Open();
  35.  
  36.     cout << "\nTest x: Write and Read handles to file…\n";
  37.     Handle myH = ::NewHandle(kSize);            // handle
  38.     (**myH) = '!';                                // set a value inside the handle
  39.     myFile.WriteHandle(myH);                    // write it down to disk
  40.     Handle result = myFile.ReadHandle();        // read the handle back
  41.     cout << "The character stored  is… " << (**result) << " and it should be ! \n";
  42.     ::DisposeHandle(result);
  43.     ::DisposeHandle(myH);
  44.  
  45.     cout << "\nTest x: Write and Read buffers to file…\n";
  46.     Ptr myBuffer = ::NewPtr(kSize);                // 100 byte buffer
  47.     for (short i = 0; i < kSize; i++)
  48.         myBuffer[i] = 'P';                        // stuff the buffer full of 'P's
  49.     myFile.Reset();                                // set mark to beginning of file
  50.     myFile.Write(myBuffer, kSize);                // write the buffer to disk
  51.  
  52.     Ptr otherBuffer = ::NewPtr(kSize);            // create another buffer
  53.     myFile.Reset();                                // reset to beginning of file
  54.     myFile.Read(otherBuffer, kSize);            // read the bytes    
  55.     for (i = 0; i < kSize; i++)
  56.         cout << otherBuffer[i];
  57.  
  58.     ::DisposePtr(otherBuffer);
  59.     ::DisposePtr(myBuffer);
  60.  
  61.     cout << "\nTest x: Create a Resource file, and write into it, and read the resource…\n";
  62.     TResourceFile myResourceFile("Resource File");
  63.     myResourceFile.Create();
  64.     myResourceFile.Open();
  65.  
  66.     if (myResourceFile.HasResourceFork())
  67.         cout << "We have a resource fork in the resource file created\n";
  68.     else
  69.         cout << "We don't have a resource fork in the resource file created.\n";
  70.  
  71.     myResourceFile.Update();
  72.     myResourceFile.Assign();
  73.  
  74.     cout << "\nTest x:Close and delete the files…\n";
  75.     myFile.Close();
  76.     myResourceFile.Close();
  77.     myFile.Delete();
  78.     myResourceFile.Delete();
  79.  
  80.     cout << "\nEnd of the TFile object test!\n";
  81. }
  82.  
  83.  
  84. // _________________________________________________________________________________________________________ //
  85. /*    Change History (most recent last):
  86.   No        Init.    Date        Comment
  87.   1            khs        12/27/92    New file
  88.   2            khs        1/14/93        Cleanup
  89. */
  90.